<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no' name='viewport'>
<title></title>
<%@ include file="/WEB-INF/component/commonCSS.jsp"%>
<!--[if lt IE 9]>
        <script src="lib/js/html5shiv.min.js"></script>
        <script src="lib/js/respond.min.js"></script>
    <![endif]-->
</head>
<body class="skin-blue sidebar-mini fixed skin-blue-light-frame">
	<section class="content-header">
		<h1>配送地区申报</h1>
		<ol class="breadcrumb">
			<li><a href="${ctx}/home.jsp"><i class="fa fa-home"></i>首页</a></li>
			<li class="active"><a href="#">交易</a></li>
			<li class="active"><a href="#">配送关系</a></li>
			<li class="active"><a href="#">配送区域申报</a></li>
		</ol>
	</section>
	<section class="content">
		<div class=" box box-success">
			<div class="box-body">
				<div class="input">
					<div class="textalign1">市：</div>
                    <div class="boxinput">
	                    <select class="textinput" id="fatherId"  name="fatherId"> 
	                     <option value="">请选择</option>
	                    <c:forEach items="${list }" var="lis">
	                    	<option value="${lis.area_id }">${lis.area_name }</option>
	                    </c:forEach>
	                    </select>
                    </div>
                    <div class="textalign">地区名称：</div>
                    <div class="boxinput">
                        <input type="text" class="textinput" id="areaName" placeholder="地区名称" maxlength="32"/>
                    </div>
                    <div class="textalign1">
					  <button id="selectArea" type="button" class="btn btn-success btn-sm" onclick="search();">查&nbsp;询</button>
				    </div>
				</div>
			</div>
		</div>
		<table class="jqgrid" id="gridlist"></table>
		<div id="gridpage"></div>
		  <div class="box box-warning bottongroup" id="bottongroup">
			<label onclick="declare();" class="btn btn-primary btn-sm">申&nbsp;报</label>
		</div>
		
	</section>
	<%@ include file="/WEB-INF/component/commonJS.jsp"%>
	<script type="text/javascript">
        $(function () {        	
		   $('.input :input').bind('keydown', function(event) {if (event.keyCode == "13") {search();}}).eq(1).focus();

            $("#gridlist").jqGrid({
                url: "${pageContext.request.contextPath}/baseDelByPs/getSelectDelAreaByPs.html",
                mtype: "POST",
                contentType : 'application/json',
                datatype: "json",
                autowidth: true,
              //  height: 315,
                colNames: [
                           '地区编码',
                           '地区名称',
                           '地区完整名称'
                           ],
                colModel: [
                    { name: 'area_id',key:true, width: 40, align: 'center' ,sortable: false},
                    { name: 'area_name', width: 60 , align: 'center',sortable: false},
                    { name: 'ar_fullname', width: 80, align: 'center',sortable: false }
                ],
                rowNum: 0,
                rownumbers: true,
                viewrecords: true,
                multiselect: true,
                caption: "地区列表",
               gridComplete: function(){
				  //数据只有一条时默认选中（参数为jqgridID）
				  selectByOneData("gridlist");
                },
                jsonReader: {
                    repeatitems: false,
                    id: "area_id"
                }
            });
            $("#gridlist").jqGrid('navGrid', '#gridpage', { add: false, edit: false, del: false, search: false, refresh: false });
            $(window).trigger("resize");
			$("#gridlist").jqGrid("setGridHeight", create());
        });
        
        //查询
        function search() {
            var areaName = $.trim($("#areaName").val());
            var fatherId = $.trim($("#fatherId").val());
            $("#gridlist").jqGrid('setGridParam',{  
                datatype:'json',
                postData:{
                        "areaName":areaName,
                        "fatherId":fatherId
                        },
                        page : 1
            }).trigger("reloadGrid"); //重新载入  
        }
      	function declare() {
  	       	//获取选中的ID及对应的名字（参数:jqgridId,名字列名，状态列名，当前操作即列表中显示的值），返回infos[0]是ID串，infos[1]是名字串
  	      var infos = batchSwitchStatus("gridlist","area_name","ar_fullname","申报","地区！");
  	      if ( !(infos instanceof Array)){
  	       		return;
  	      }
        	  $.HN.message.confirm('确定申报以下地区吗？<br/>'+infos[1].replace(/\,/g,"<br/>"), '', '').on(function (e) {
                  if (e) {
                  	$.ajax({
                          url:"${ctx}/baseDelByPs/batchDeclare.html",//action地址
                          data: {param:infos[0]},//传值
                          type: "post",//执行方式get or post 默认以post方式执行
                          dataType:"json",
                          success: function (result) {//执行成功后 提示
                              if (result.success){
                              	top.$.HN.message.alert("成功申报"+infos[0].split(",").length+"个地区！","", "success");
                              	search($("#gridlist").getGridParam("page"));
                             } else {
                          	   top.$.HN.message.alert("操作失败！！","", "error");
                             } 
                          }
                      });
                  }
              });
      	}

        
    </script>
</body>
</html>